<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class PlatCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public $resource;

    public function __construct($resource)
    {
        $this->resource = $resource;
        parent::__construct($resource);
    }

    public function toArray($request)
    {
        if ($this->resource->count() >= 1) {
            foreach ($this->collection as $key => $item) {
                $data[$key]['main_game_plat_name'] = $item->main_game_plat_name;
                $data[$key]['main_game_plat_code'] = $item->main_game_plat_code;
            }
            $this->resource->setCollection(collect($data));
            return [
                $this->resource
            ];
        } else {
            return [];
        }

    }
}
